#include <iostream>
#include <string>
#include <vector>

#include "baldr/graphreader.h"
#include "baldr/rapidjson_utils.h"
#include "loki/worker.h"
#include "thor/worker.h"

#include "test.h"
#include "utils.h"

using namespace valhalla;
using namespace valhalla::thor;
using namespace valhalla::sif;
using namespace valhalla::loki;
using namespace valhalla::baldr;
using namespace valhalla::midgard;
using namespace valhalla::tyr;

namespace {

const auto config = test::json_to_pt(R"({
    "mjolnir":{"tile_dir":"test/data/utrecht_tiles", "concurrency": 1},
    "loki":{
      "actions":["sources_to_targets"],
      "logging":{"long_request": 100},
      "service_defaults":{"minimum_reachability": 50,"radius": 0,"search_cutoff": 35000, "node_snap_tolerance": 5, "street_side_tolerance": 5, "street_side_max_distance": 1000, "heading_tolerance": 60}
    },
    "thor":{
      "logging":{"long_request": 100}
    },
    "meili":{
      "grid": {"cache_size": 100240,"size": 500},
      "default": {"breakage_distance": 2000}
    },
    "service_limits": {
      "auto": {"max_distance": 5000000.0, "max_locations": 20,"max_matrix_distance": 400000.0,"max_matrix_locations": 50},
      "auto_shorter": {"max_distance": 5000000.0,"max_locations": 20,"max_matrix_distance": 400000.0,"max_matrix_locations": 50},
      "bicycle": {"max_distance": 500000.0,"max_locations": 50,"max_matrix_distance": 200000.0,"max_matrix_locations": 50},
      "bus": {"max_distance": 5000000.0,"max_locations": 50,"max_matrix_distance": 400000.0,"max_matrix_locations": 50},
      "hov": {"max_distance": 5000000.0,"max_locations": 20,"max_matrix_distance": 400000.0,"max_matrix_locations": 50},
      "taxi": {"max_distance": 5000000.0,"max_locations": 20,"max_matrix_distance": 400000.0,"max_matrix_locations": 50},
      "isochrone": {"max_contours": 4,"max_distance": 25000.0,"max_locations": 1,"max_time": 120},
      "max_avoid_locations": 50,"max_radius": 200,"max_reachability": 100,"max_alternates":2,
      "multimodal": {"max_distance": 500000.0,"max_locations": 50,"max_matrix_distance": 0.0,"max_matrix_locations": 0},
      "pedestrian": {"max_distance": 250000.0,"max_locations": 50,"max_matrix_distance": 200000.0,"max_matrix_locations": 50,"max_transit_walking_distance": 10000,"min_transit_walking_distance": 1},
      "skadi": {"max_shape": 750000,"min_resample": 10.0},
      "trace": {"max_distance": 200000.0,"max_gps_accuracy": 100.0,"max_search_radius": 100,"max_shape": 16000,"max_best_paths":4,"max_best_paths_shape":100},
      "transit": {"max_distance": 500000.0,"max_locations": 50,"max_matrix_distance": 200000.0,"max_matrix_locations": 50},
      "truck": {"max_distance": 5000000.0,"max_locations": 20,"max_matrix_distance": 400000.0,"max_matrix_locations": 50}
    }
  })");

void try_isochrone(GraphReader& reader,
                   loki_worker_t& loki_worker,
                   thor_worker_t& thor_worker,
                   const std::string& test_request,
                   const std::string& expected_json) {
  // compute the isochrone
  Api request;
  ParseApi(test_request, Options::isochrone, request);
  loki_worker.isochrones(request);
  auto response_json = thor_worker.isochrones(request);

  // Parse isochrone json responses
  rapidjson::Document response, expected_response;
  response.Parse(response_json);
  expected_response.Parse(expected_json);

  loki_worker.cleanup();
  thor_worker.cleanup();

  ASSERT_EQ(response, expected_response) << "Actual:   " << response_json << std::endl
                                         << "Expected: " << expected_json;

} // namespace

TEST(Isochronies, Basic) {
  // Test setup
  loki_worker_t loki_worker(config);
  thor_worker_t thor_worker(config);
  GraphReader reader(config.get_child("mjolnir"));

// Test auto isochrone with one contour
// 32bit builds fail in release mode we'll look at this separately
#if _WIN64 || __amd64__
  {
    const auto expected =
        R"({"features":[{"properties":{"fill-opacity":0.33,"color":"#bf4040","fillColor":"#bf4040","fillOpacity":0.33,"contour":15,"opacity":0.33,"fill":"#bf4040"},"geometry":{"coordinates":[[5.064342,52.135956],[5.046322,52.130409],[5.036321,52.122616],[5.031586,52.123940],[5.035038,52.120937],[5.033321,52.119022],[5.015980,52.128281],[5.029667,52.118938],[5.025681,52.106937],[5.032321,52.115650],[5.040556,52.114174],[5.049912,52.109940],[5.053091,52.103710],[5.060321,52.101719],[5.059572,52.099686],[5.054253,52.099007],[5.058738,52.098354],[5.057434,52.096939],[5.060148,52.094765],[5.062321,52.096302],[5.063633,52.093933],[5.059526,52.090939],[5.062546,52.088715],[5.058321,52.089424],[5.046380,52.085934],[5.049034,52.082939],[5.042563,52.072693],[5.036321,52.081791],[5.034321,52.079700],[5.026321,52.079132],[5.026060,52.075935],[5.021580,52.073936],[5.025514,52.073132],[5.026585,52.069675],[5.022974,52.069286],[5.022321,52.066444],[5.018321,52.066845],[5.021797,52.064934],[5.017061,52.060680],[5.031321,52.071278],[5.032321,52.068470],[5.032818,52.070442],[5.037321,52.070568],[5.054321,52.068134],[5.057321,52.065502],[5.059321,52.067120],[5.063448,52.066063],[5.065723,52.057343],[5.068321,52.055504],[5.069958,52.058304],[5.073717,52.057941],[5.071006,52.057255],[5.069663,52.051598],[5.067322,52.053688],[5.066027,52.051937],[5.072321,52.046574],[5.093321,52.046230],[5.094085,52.048176],[5.098321,52.046173],[5.100216,52.050045],[5.107510,52.051125],[5.111447,52.050064],[5.111764,52.046379],[5.114138,52.049122],[5.114850,52.046467],[5.118321,52.046108],[5.120321,52.049114],[5.141321,52.050201],[5.142321,52.048126],[5.145163,52.052097],[5.155321,52.051182],[5.159078,52.054939],[5.155184,52.057072],[5.159891,52.059505],[5.152190,52.058807],[5.149158,52.065933],[5.152321,52.068089],[5.158979,52.064278],[5.159005,52.066620],[5.152072,52.070938],[5.161815,52.079445],[5.163098,52.091938],[5.153594,52.102943],[5.161614,52.105232],[5.154035,52.104652],[5.147321,52.116318],[5.152837,52.104427],[5.148944,52.105316],[5.147321,52.103477],[5.145321,52.109657],[5.142321,52.103588],[5.136321,52.105732],[5.132321,52.103565],[5.132321,52.106949],[5.129321,52.104454],[5.121088,52.105938],[5.129809,52.103428],[5.129321,52.099972],[5.132609,52.102650],[5.138787,52.101936],[5.139545,52.099937],[5.137113,52.096149],[5.130321,52.093784],[5.126788,52.095402],[5.127321,52.098076],[5.126321,52.092896],[5.123102,52.092941],[5.124637,52.090622],[5.120321,52.089405],[5.112797,52.092937],[5.117321,52.093410],[5.117321,52.095554],[5.121540,52.096939],[5.121321,52.101917],[5.117148,52.101936],[5.115321,52.106358],[5.112321,52.101788],[5.111569,52.103939],[5.108321,52.102634],[5.105321,52.105484],[5.102321,52.103481],[5.097321,52.105156],[5.099359,52.108978],[5.097092,52.109161],[5.088061,52.105194],[5.087158,52.102772],[5.078321,52.105389],[5.082674,52.099586],[5.070321,52.099430],[5.068321,52.103615],[5.068321,52.100319],[5.060934,52.106941],[5.063321,52.108566],[5.066544,52.106712],[5.064803,52.111938],[5.057869,52.116940],[5.064297,52.117939],[5.056064,52.120193],[5.047809,52.117428],[5.041121,52.124741],[5.048685,52.130569],[5.064342,52.135956]],"type":"LineString"},"type":"Feature"}],"type":"FeatureCollection"})";
    const auto request =
        R"({"locations":[{"lat":52.078937,"lon":5.115321}],"costing":"auto","contours":[{"time":15}],"polygons":false,"denoise":0.2,"generalize":150})";
    try_isochrone(reader, loki_worker, thor_worker, request, expected);
  }

  {
    const auto expected =
        R"({"features":[{"properties":{"fillOpacity":0.33,"color":"#bf4040","fill":"#bf4040","fillColor":"#bf4040","contour":15,"opacity":0.33,"fill-opacity":0.33},"type":"Feature","geometry":{"coordinates":[[[5.116656,52.105274],[5.116321,52.105682],[5.115321,52.104362],[5.114321,52.104870],[5.113321,52.104645],[5.112321,52.104927],[5.111321,52.104366],[5.110504,52.105122],[5.109321,52.105293],[5.108883,52.104939],[5.109858,52.104477],[5.109999,52.103939],[5.108321,52.102581],[5.107902,52.104515],[5.106321,52.105423],[5.104321,52.104935],[5.101321,52.105137],[5.100321,52.104622],[5.098351,52.104973],[5.094643,52.103939],[5.094321,52.101654],[5.095782,52.101402],[5.098321,52.098530],[5.100321,52.098286],[5.101321,52.097286],[5.103321,52.097294],[5.103321,52.095806],[5.103030,52.096649],[5.102321,52.096790],[5.095322,52.096756],[5.094321,52.097733],[5.088078,52.097698],[5.087986,52.098270],[5.089509,52.098751],[5.089676,52.099583],[5.090808,52.099934],[5.089321,52.100563],[5.088321,52.100250],[5.087321,52.101749],[5.085685,52.100941],[5.085321,52.099861],[5.082504,52.098938],[5.085321,52.098564],[5.085574,52.097687],[5.081321,52.097309],[5.080321,52.097908],[5.080216,52.096836],[5.081820,52.095940],[5.079321,52.095551],[5.078764,52.094940],[5.079911,52.093525],[5.081638,52.092941],[5.078917,52.092342],[5.078764,52.090939],[5.079894,52.088512],[5.081786,52.087940],[5.081321,52.087151],[5.080253,52.087009],[5.080024,52.083939],[5.081627,52.082245],[5.081661,52.079941],[5.080817,52.079441],[5.078733,52.079350],[5.077898,52.079514],[5.077321,52.080441],[5.076321,52.080605],[5.076161,52.079941],[5.077321,52.078663],[5.082321,52.078289],[5.083059,52.076675],[5.084321,52.075779],[5.084602,52.074661],[5.083025,52.073940],[5.084637,52.072254],[5.084649,52.071609],[5.082178,52.071796],[5.079114,52.074730],[5.078986,52.075603],[5.077870,52.075939],[5.078321,52.076950],[5.077321,52.077065],[5.076982,52.076279],[5.076105,52.076153],[5.075321,52.075348],[5.071809,52.074940],[5.074321,52.074566],[5.075011,52.073627],[5.076321,52.073380],[5.076705,52.072937],[5.076615,52.071644],[5.074913,52.070938],[5.075072,52.069687],[5.076196,52.068939],[5.075956,52.065575],[5.081321,52.065277],[5.084188,52.062805],[5.086740,52.062355],[5.087321,52.061684],[5.089321,52.061813],[5.088583,52.062935],[5.089038,52.064220],[5.090321,52.064342],[5.090967,52.063583],[5.092715,52.063332],[5.093321,52.062637],[5.093758,52.063934],[5.094321,52.064175],[5.097864,52.060482],[5.100725,52.058342],[5.101321,52.056839],[5.102897,52.057362],[5.104321,52.056187],[5.106467,52.056084],[5.105990,52.054939],[5.105321,52.054504],[5.104326,52.054947],[5.103601,52.054657],[5.103544,52.053940],[5.102666,52.053596],[5.102436,52.052830],[5.100936,52.052326],[5.100321,52.051449],[5.096518,52.051132],[5.096321,52.051628],[5.096117,52.051144],[5.097017,52.050629],[5.102726,52.050346],[5.104321,52.048439],[5.104456,52.050072],[5.103623,52.051937],[5.104321,52.052246],[5.104827,52.051441],[5.107707,52.051323],[5.108321,52.050499],[5.111756,52.050373],[5.112322,52.049015],[5.114427,52.050934],[5.113321,52.052040],[5.112897,52.051365],[5.111029,52.051643],[5.112003,52.052937],[5.112127,52.055130],[5.113819,52.055435],[5.115321,52.056652],[5.121321,52.057217],[5.123321,52.059147],[5.125321,52.059219],[5.126321,52.058228],[5.127517,52.059135],[5.128170,52.056786],[5.131797,52.056416],[5.132321,52.055954],[5.132879,52.056385],[5.136351,52.056904],[5.137321,52.057510],[5.138801,52.057419],[5.139321,52.056988],[5.139910,52.058350],[5.141636,52.059628],[5.141756,52.060940],[5.143844,52.062416],[5.144320,52.064152],[5.144811,52.062428],[5.150010,52.057629],[5.151765,52.057381],[5.152321,52.055862],[5.152514,52.058128],[5.150910,52.058525],[5.148041,52.061943],[5.148321,52.062508],[5.149321,52.062332],[5.149608,52.062653],[5.148851,52.063942],[5.148973,52.065941],[5.151094,52.068169],[5.152321,52.068295],[5.153321,52.067333],[5.154649,52.067268],[5.156321,52.065609],[5.158179,52.065941],[5.156867,52.066486],[5.155649,52.068264],[5.154321,52.068497],[5.153069,52.069687],[5.153321,52.070431],[5.155321,52.070580],[5.155561,52.071175],[5.152321,52.071522],[5.151321,52.070641],[5.149109,52.072941],[5.150066,52.073940],[5.150122,52.075138],[5.151321,52.076328],[5.152970,52.074936],[5.153321,52.073833],[5.153953,52.075306],[5.155539,52.075722],[5.155433,52.078049],[5.153321,52.076458],[5.151885,52.077938],[5.153321,52.079460],[5.154563,52.079697],[5.155321,52.080734],[5.156283,52.080940],[5.156773,52.082939],[5.156048,52.083210],[5.155575,52.082687],[5.154026,52.082237],[5.153663,52.081596],[5.152321,52.081520],[5.151579,52.080681],[5.149875,52.080387],[5.149321,52.079674],[5.149101,52.080940],[5.150076,52.081936],[5.149322,52.082691],[5.147795,52.082466],[5.146440,52.080822],[5.145147,52.080936],[5.145215,52.082047],[5.145978,52.082283],[5.147321,52.084141],[5.149321,52.084198],[5.150321,52.083221],[5.153321,52.083298],[5.154095,52.083942],[5.153717,52.085938],[5.154674,52.087585],[5.155728,52.087940],[5.154321,52.089520],[5.150321,52.089470],[5.149642,52.086941],[5.149321,52.086666],[5.149100,52.086941],[5.149098,52.091160],[5.152321,52.091423],[5.153321,52.090771],[5.154321,52.090908],[5.153684,52.091301],[5.153568,52.093185],[5.152137,52.094128],[5.150321,52.092548],[5.149321,52.093414],[5.148321,52.092609],[5.147380,52.092937],[5.147984,52.094280],[5.149538,52.094723],[5.149871,52.095390],[5.150894,52.095512],[5.151321,52.095196],[5.151905,52.097355],[5.154284,52.097939],[5.153525,52.098141],[5.153330,52.098946],[5.152919,52.098343],[5.152321,52.098282],[5.150918,52.098534],[5.150321,52.099579],[5.147181,52.099079],[5.146686,52.098934],[5.148722,52.098339],[5.148619,52.097645],[5.145321,52.097626],[5.144805,52.097939],[5.146219,52.098938],[5.145744,52.099941],[5.146544,52.100945],[5.146321,52.101742],[5.144989,52.101273],[5.144898,52.099941],[5.144321,52.099483],[5.142838,52.100941],[5.143321,52.101654],[5.144603,52.101940],[5.142791,52.102940],[5.140321,52.102592],[5.140028,52.102238],[5.137537,52.102158],[5.136729,52.102348],[5.136321,52.103081],[5.135886,52.102375],[5.134052,52.101940],[5.133929,52.099548],[5.135321,52.099365],[5.135707,52.098938],[5.135471,52.096790],[5.134633,52.096622],[5.134353,52.095905],[5.133705,52.095940],[5.132703,52.096325],[5.132321,52.096977],[5.130460,52.097076],[5.129322,52.098137],[5.128321,52.098118],[5.127058,52.099674],[5.124401,52.099018],[5.123968,52.099941],[5.124379,52.102940],[5.120321,52.103275],[5.119322,52.102711],[5.116656,52.105274]]],"type":"Polygon"}}],"type":"FeatureCollection"})";
    const auto request =
        R"({"locations":[{"lat":52.078937,"lon":5.115321}],"costing":"bicycle","contours":[{"time":15}],"polygons":true,"denoise":0.2})";
    try_isochrone(reader, loki_worker, thor_worker, request, expected);
  }

  {
    const auto expected =
        R"({"features":[{"properties":{"fillOpacity":0.33,"color":"#bf4040","fill":"#bf4040","fillColor":"#bf4040","contour":15,"opacity":0.33,"fill-opacity":0.33},"type":"Feature","geometry":{"coordinates":[[5.116656,52.105274],[5.116321,52.105682],[5.115321,52.104362],[5.114321,52.104870],[5.113321,52.104645],[5.112321,52.104927],[5.111321,52.104366],[5.110504,52.105122],[5.109321,52.105293],[5.108883,52.104939],[5.109858,52.104477],[5.109999,52.103939],[5.108321,52.102581],[5.107902,52.104515],[5.106321,52.105423],[5.104321,52.104935],[5.101321,52.105137],[5.100321,52.104622],[5.098351,52.104973],[5.094643,52.103939],[5.094321,52.101654],[5.095782,52.101402],[5.098321,52.098530],[5.100321,52.098286],[5.101321,52.097286],[5.103321,52.097294],[5.103321,52.095806],[5.103030,52.096649],[5.102321,52.096790],[5.095322,52.096756],[5.094321,52.097733],[5.088078,52.097698],[5.087986,52.098270],[5.089509,52.098751],[5.089676,52.099583],[5.090808,52.099934],[5.089321,52.100563],[5.088321,52.100250],[5.087321,52.101749],[5.085685,52.100941],[5.085321,52.099861],[5.082504,52.098938],[5.085321,52.098564],[5.085574,52.097687],[5.081321,52.097309],[5.080321,52.097908],[5.080216,52.096836],[5.081820,52.095940],[5.079321,52.095551],[5.078764,52.094940],[5.079911,52.093525],[5.081638,52.092941],[5.078917,52.092342],[5.078764,52.090939],[5.079894,52.088512],[5.081786,52.087940],[5.081321,52.087151],[5.080253,52.087009],[5.080024,52.083939],[5.081627,52.082245],[5.081661,52.079941],[5.080817,52.079441],[5.078733,52.079350],[5.077898,52.079514],[5.077321,52.080441],[5.076321,52.080605],[5.076161,52.079941],[5.077321,52.078663],[5.082321,52.078289],[5.083059,52.076675],[5.084321,52.075779],[5.084602,52.074661],[5.083025,52.073940],[5.084637,52.072254],[5.084649,52.071609],[5.082178,52.071796],[5.079114,52.074730],[5.078986,52.075603],[5.077870,52.075939],[5.078321,52.076950],[5.077321,52.077065],[5.076982,52.076279],[5.076105,52.076153],[5.075321,52.075348],[5.071809,52.074940],[5.074321,52.074566],[5.075011,52.073627],[5.076321,52.073380],[5.076705,52.072937],[5.076615,52.071644],[5.074913,52.070938],[5.075072,52.069687],[5.076196,52.068939],[5.075956,52.065575],[5.081321,52.065277],[5.084188,52.062805],[5.086740,52.062355],[5.087321,52.061684],[5.089321,52.061813],[5.088583,52.062935],[5.089038,52.064220],[5.090321,52.064342],[5.090967,52.063583],[5.092715,52.063332],[5.093321,52.062637],[5.093758,52.063934],[5.094321,52.064175],[5.097864,52.060482],[5.100725,52.058342],[5.101321,52.056839],[5.102897,52.057362],[5.104321,52.056187],[5.106467,52.056084],[5.105990,52.054939],[5.105321,52.054504],[5.104326,52.054947],[5.103601,52.054657],[5.103544,52.053940],[5.102666,52.053596],[5.102436,52.052830],[5.100936,52.052326],[5.100321,52.051449],[5.096518,52.051132],[5.096321,52.051628],[5.096117,52.051144],[5.097017,52.050629],[5.102726,52.050346],[5.104321,52.048439],[5.104456,52.050072],[5.103623,52.051937],[5.104321,52.052246],[5.104827,52.051441],[5.107707,52.051323],[5.108321,52.050499],[5.111756,52.050373],[5.112322,52.049015],[5.114427,52.050934],[5.113321,52.052040],[5.112897,52.051365],[5.111029,52.051643],[5.112003,52.052937],[5.112127,52.055130],[5.113819,52.055435],[5.115321,52.056652],[5.121321,52.057217],[5.123321,52.059147],[5.125321,52.059219],[5.126321,52.058228],[5.127517,52.059135],[5.128170,52.056786],[5.131797,52.056416],[5.132321,52.055954],[5.132879,52.056385],[5.136351,52.056904],[5.137321,52.057510],[5.138801,52.057419],[5.139321,52.056988],[5.139910,52.058350],[5.141636,52.059628],[5.141756,52.060940],[5.143844,52.062416],[5.144320,52.064152],[5.144811,52.062428],[5.150010,52.057629],[5.151765,52.057381],[5.152321,52.055862],[5.152514,52.058128],[5.150910,52.058525],[5.148041,52.061943],[5.148321,52.062508],[5.149321,52.062332],[5.149608,52.062653],[5.148851,52.063942],[5.148973,52.065941],[5.151094,52.068169],[5.152321,52.068295],[5.153321,52.067333],[5.154649,52.067268],[5.156321,52.065609],[5.158179,52.065941],[5.156867,52.066486],[5.155649,52.068264],[5.154321,52.068497],[5.153069,52.069687],[5.153321,52.070431],[5.155321,52.070580],[5.155561,52.071175],[5.152321,52.071522],[5.151321,52.070641],[5.149109,52.072941],[5.150066,52.073940],[5.150122,52.075138],[5.151321,52.076328],[5.152970,52.074936],[5.153321,52.073833],[5.153953,52.075306],[5.155539,52.075722],[5.155433,52.078049],[5.153321,52.076458],[5.151885,52.077938],[5.153321,52.079460],[5.154563,52.079697],[5.155321,52.080734],[5.156283,52.080940],[5.156773,52.082939],[5.156048,52.083210],[5.155575,52.082687],[5.154026,52.082237],[5.153663,52.081596],[5.152321,52.081520],[5.151579,52.080681],[5.149875,52.080387],[5.149321,52.079674],[5.149101,52.080940],[5.150076,52.081936],[5.149322,52.082691],[5.147795,52.082466],[5.146440,52.080822],[5.145147,52.080936],[5.145215,52.082047],[5.145978,52.082283],[5.147321,52.084141],[5.149321,52.084198],[5.150321,52.083221],[5.153321,52.083298],[5.154095,52.083942],[5.153717,52.085938],[5.154674,52.087585],[5.155728,52.087940],[5.154321,52.089520],[5.150321,52.089470],[5.149642,52.086941],[5.149321,52.086666],[5.149100,52.086941],[5.149098,52.091160],[5.152321,52.091423],[5.153321,52.090771],[5.154321,52.090908],[5.153684,52.091301],[5.153568,52.093185],[5.152137,52.094128],[5.150321,52.092548],[5.149321,52.093414],[5.148321,52.092609],[5.147380,52.092937],[5.147984,52.094280],[5.149538,52.094723],[5.149871,52.095390],[5.150894,52.095512],[5.151321,52.095196],[5.151905,52.097355],[5.154284,52.097939],[5.153525,52.098141],[5.153330,52.098946],[5.152919,52.098343],[5.152321,52.098282],[5.150918,52.098534],[5.150321,52.099579],[5.147181,52.099079],[5.146686,52.098934],[5.148722,52.098339],[5.148619,52.097645],[5.145321,52.097626],[5.144805,52.097939],[5.146219,52.098938],[5.145744,52.099941],[5.146544,52.100945],[5.146321,52.101742],[5.144989,52.101273],[5.144898,52.099941],[5.144321,52.099483],[5.142838,52.100941],[5.143321,52.101654],[5.144603,52.101940],[5.142791,52.102940],[5.140321,52.102592],[5.140028,52.102238],[5.137537,52.102158],[5.136729,52.102348],[5.136321,52.103081],[5.135886,52.102375],[5.134052,52.101940],[5.133929,52.099548],[5.135321,52.099365],[5.135707,52.098938],[5.135471,52.096790],[5.134633,52.096622],[5.134353,52.095905],[5.133705,52.095940],[5.132703,52.096325],[5.132321,52.096977],[5.130460,52.097076],[5.129322,52.098137],[5.128321,52.098118],[5.127058,52.099674],[5.124401,52.099018],[5.123968,52.099941],[5.124379,52.102940],[5.120321,52.103275],[5.119322,52.102711],[5.116656,52.105274]],"type":"LineString"}},{"geometry":{"coordinates":[[5.115327,52.078941]],"type":"MultiPoint"},"type":"Feature","properties":{"location_index":0,"type":"snapped"}},{"geometry":{"coordinates":[5.115321,52.078938],"type":"Point"},"type":"Feature","properties":{"location_index":0,"type":"input"}}],"type":"FeatureCollection"})";
    const auto request =
        R"({"locations":[{"lat":52.078937,"lon":5.115321}],"costing":"bicycle","contours":[{"time":15}],"show_locations":true})";
    try_isochrone(reader, loki_worker, thor_worker, request, expected);
  }
#endif
}

} // namespace

int main(int argc, char* argv[]) {
  // user wants to try it
  if (argc > 1) {
    loki_worker_t loki_worker(config);
    thor_worker_t thor_worker(config);
    GraphReader reader(config.get_child("mjolnir"));
    Api request;
    ParseApi(argv[1], Options::isochrone, request);
    loki_worker.isochrones(request);
    std::cout << thor_worker.isochrones(request) << std::endl;
    return EXIT_SUCCESS;
  }
  // Silence logs (especially long request logging)
  logging::Configure({{"type", ""}});
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
